package com.fr.report.script.function;

import com.fr.base.core.DateUtils;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import java.util.Date;

public class DAYSOFQUARTER extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length == 0)
      return new Integer(0);
    Date localDate = (paramArrayOfObject.length == 0) ? new Date() : DateUtils.object2Date(paramArrayOfObject[0], false);
    int i = localDate.getMonth();
    if ((i == 1) || (i == 2) || (i == 3))
      return new Integer((int)DateUtils.subtractDate(new Date(localDate.getYear(), 3, localDate.getDate()), new Date(localDate.getYear(), 0, localDate.getDate()), "d"));
    if ((i == 4) || (i == 5) || (i == 6))
      return new Integer(91);
    if ((i == 7) || (i == 8) || (i == 9))
      return new Integer(92);
    if ((i == 10) || (i == 11) || (i == 12))
      return new Integer(92);
    return null;
  }

  public Function.Type getType()
  {
    return Function.DATETIME;
  }

  public String getCN()
  {
    return "DAYSOFQUARTER(date): 返回从1900年1月后某年某季度的天数。\n示例：\nDAYSOFQUARTER(\"2009-02-01\")等于90。\nDAYSOFQUARTER(\"2009/05/05\")等于91。";
  }

  public String getEN()
  {
    return "DAYSOFQUARTER(date):return the days of one day in a quarter.\nExample:\nDAYSOFQUARTER(\"2009-02-01\") = 90.\nDAYSOFQUARTER(\"2009/05/05\") = 91.";
  }
}